package com.ymatou.iapi.userservice.testcase;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.json.JSONObject;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.ymatou.iapi.userregister.parameter.SellerRegisterBean;
import com.ymatou.iapi.userregister.parameter.UserRegisterInfoRequestDtoBean;
import com.ymatou.iapi.userregister.service.UserRegisterInfoRequestDtoCall;
import com.ymatou.iapi.userservice.parameter.BatchUserBriefInfoByLoginIdBean;
import com.ymatou.iapi.userservice.service.BatchUserBriefInfoByLoginIdCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.JUserCallService;
import com.ymttest.business.service.LiveShopUserCallService;
/**
*批量获取用户简要信息（ByLoginId）
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_BatchUserBriefInfoByLoginId{
	private static BatchUserBriefInfoByLoginIdBean batchuserbriefinfobyloginidBean;
	private static BatchUserBriefInfoByLoginIdCall batchuserbriefinfobyloginidCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("批量获取用户简要信息（ByLoginId）");
	}

	@Before
	public void caseUp() {
		batchuserbriefinfobyloginidBean=new BatchUserBriefInfoByLoginIdBean();
		batchuserbriefinfobyloginidCall=new BatchUserBriefInfoByLoginIdCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(batchuserbriefinfobyloginidCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_BatchUserBriefInfoByLoginId_001() {
		Logger.start(true,"批量获取用户简要信息（ByLoginId）成功");
		try {
			List<String> LoginIdList = new ArrayList<>();

			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);

			JsonObject registerResult = urrc.getJsonObject().get("Result").getAsJsonObject();
			String token = registerResult.get("Token").getAsString();
			int uid = urrc.getUserid();
			LoginIdList.add(regbean.getLoginId());

			batchuserbriefinfobyloginidBean.setLoginIdList(LoginIdList);
			batchuserbriefinfobyloginidCall.setData(batchuserbriefinfobyloginidBean);
			batchuserbriefinfobyloginidCall.callService();
			Logger.verifyEquals("200", batchuserbriefinfobyloginidCall.getString("ResponseCode"), "验证ResponseCode");
			Logger.verifyEquals("true", batchuserbriefinfobyloginidCall.getString("Success"), "验证Success");
			JsonArray Result = batchuserbriefinfobyloginidCall.getJsonObject().get("Result").getAsJsonArray();
			Logger.verifyEquals(1, Result.size(), "验证Result.size");
			for (JsonElement jsonElement : Result) {
				Logger.verifyEquals(regbean.getLoginId(), jsonElement.getAsJsonObject().get("LoginId").getAsString(), "验证LoginId");
				Logger.verifyEquals(regbean.getLoginMobile(), jsonElement.getAsJsonObject().get("LoginMobile").getAsString(), "验证LoginMobile");
				Logger.verifyEquals("1", jsonElement.getAsJsonObject().get("UserLevel").getAsString(), "验证UserLevel");
				Logger.verifyEquals(regbean.getRegisterType(), jsonElement.getAsJsonObject().get("UserType").getAsInt(), "验证UserType");
				// 默认头像地址
				Logger.verifyEquals("http://staticontent.ymatou.com/app/userlogo/mj.jpg", jsonElement.getAsJsonObject().get("LogoUrl").getAsString(), "验证UserType");
				Logger.verifyEquals("0", jsonElement.getAsJsonObject().get("UserSystem").getAsString(), "验证UserSystem");
			}
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_BatchUserBriefInfoByLoginId_002() {
		Logger.start(true,"不输入loginid失败");
		try {
			List<String> LoginIdList = new ArrayList<>();
			batchuserbriefinfobyloginidBean.setLoginIdList(LoginIdList);
			batchuserbriefinfobyloginidCall.setData(batchuserbriefinfobyloginidBean);
			batchuserbriefinfobyloginidCall.callService();			
			Logger.verifyEquals("100", batchuserbriefinfobyloginidCall.getString("ResponseCode"), "验证ResponseCode");
			Logger.verifyIsContains("用户Id列表不能为空", batchuserbriefinfobyloginidCall.getString("LastErrorMessage"), "验证LastErrorMessage");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_BatchUserBriefInfoByLoginId_003() {
		Logger.start(true,"输入多个loginid成功");
		try {
			List<String> LoginIdList = new ArrayList<>();
			Map<String, UserRegisterInfoRequestDtoBean> m = new HashMap<String, UserRegisterInfoRequestDtoBean>();
			for (int i = 0; i < 5; i++) {
				UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
				UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);
				JsonObject registerResult = urrc.getJsonObject().get("Result").getAsJsonObject();
				String token = registerResult.get("Token").getAsString();
				int uid = urrc.getUserid();
				LoginIdList.add(regbean.getLoginId());
				m.put(regbean.getLoginId(), regbean);
			}
			batchuserbriefinfobyloginidBean.setLoginIdList(LoginIdList);
			batchuserbriefinfobyloginidCall.setData(batchuserbriefinfobyloginidBean);
			batchuserbriefinfobyloginidCall.callService();			
			Logger.verifyEquals("200", batchuserbriefinfobyloginidCall.getString("ResponseCode"), "验证ResponseCode");
			Logger.verifyEquals("true", batchuserbriefinfobyloginidCall.getString("Success"), "验证Success");
			JsonArray Result = batchuserbriefinfobyloginidCall.getJsonObject().get("Result").getAsJsonArray();
			Logger.verifyEquals(LoginIdList.size(), Result.size(), "验证Result.size");
			for (JsonElement jsonElement : Result) {
				UserRegisterInfoRequestDtoBean regbean = m.get(jsonElement.getAsJsonObject().get("LoginId").getAsString());
				Logger.verifyEquals(regbean.getLoginId(), jsonElement.getAsJsonObject().get("LoginId").getAsString(), "验证LoginId");
				Logger.verifyEquals(regbean.getLoginMobile(), jsonElement.getAsJsonObject().get("LoginMobile").getAsString(), "验证LoginMobile");
				// 默认头像地址
				Logger.verifyEquals("1", jsonElement.getAsJsonObject().get("UserLevel").getAsString(), "验证UserLevel");
				Logger.verifyEquals(regbean.getRegisterType(), jsonElement.getAsJsonObject().get("UserType").getAsInt(), "验证UserType");
				// 默认头像地址
				Logger.verifyEquals("http://staticontent.ymatou.com/app/userlogo/mj.jpg", jsonElement.getAsJsonObject().get("LogoUrl").getAsString(), "验证UserType");
				Logger.verifyEquals("0", jsonElement.getAsJsonObject().get("UserSystem").getAsString(), "验证UserSystem");
				Logger.verifyEquals("0", jsonElement.getAsJsonObject().get("UserState").getAsString(), "验证UserState");
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_BatchUserBriefInfoByLoginId_004() {
		Logger.start(true,"批量获取用户简要信息（ByLoginId）成功,usersystem微店直播");
		try {
			List<String> LoginIdList = new ArrayList<>();

			SellerRegisterBean regbean=LiveShopUserCallService.initSellerReg();
			JSONObject urrc = LiveShopUserCallService.LiveShopSellerRegister(regbean);

			LoginIdList.add(regbean.getLoginId());

			batchuserbriefinfobyloginidBean.setLoginIdList(LoginIdList);
			batchuserbriefinfobyloginidCall.setData(batchuserbriefinfobyloginidBean);
			batchuserbriefinfobyloginidCall.callService();
			Logger.verifyEquals("200", batchuserbriefinfobyloginidCall.getString("ResponseCode"), "验证ResponseCode");
			Logger.verifyEquals("true", batchuserbriefinfobyloginidCall.getString("Success"), "验证Success");
			JsonArray Result = batchuserbriefinfobyloginidCall.getJsonObject().get("Result").getAsJsonArray();
			Logger.verifyEquals(1, Result.size(), "验证Result.size");
			for (JsonElement jsonElement : Result) {
				Logger.verifyEquals(regbean.getLoginId(), jsonElement.getAsJsonObject().get("LoginId").getAsString(), "验证LoginId");
				Logger.verifyEquals(regbean.getLoginMobile(), jsonElement.getAsJsonObject().get("LoginMobile").getAsString(), "验证LoginMobile");
				Logger.verifyEquals("1", jsonElement.getAsJsonObject().get("UserLevel").getAsString(), "验证UserLevel");
				Logger.verifyEquals(1, jsonElement.getAsJsonObject().get("UserType").getAsInt(), "验证UserType");
				// 默认头像地址
				Logger.verifyEquals("http://staticontent.ymatou.com/app/userlogo/ms.jpg", jsonElement.getAsJsonObject().get("LogoUrl").getAsString(), "验证UserType");
				Logger.verifyEquals("1", jsonElement.getAsJsonObject().get("UserSystem").getAsString(), "验证UserSystem");
			}
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}